package com.xyzwps.boofcv;

import boofcv.alg.fiducial.qrcode.QrCode;
import boofcv.alg.fiducial.qrcode.QrCodeEncoder;
import boofcv.io.image.ConvertBufferedImage;
import boofcv.io.image.UtilImageIO;

import java.awt.image.BufferedImage;

public class ExampleRenderQrCode {
    public static void main(String[] args) {
        // Uses a flow pattern to specify the QR Code. You can control all aspects of the QR
        // like specifying the version, mask, and message types or let it select all of that for you.
        QrCode qr = new QrCodeEncoder().
                setVersion(4).
                setError(QrCode.ErrorLevel.M).
                addAutomatic("This is a Test ん鞠").fixate();
        // NOTE: The final function you call must be fixate() that's how it knows its done

        // QrCodeGenerator is the base class with all the logic and the children tell it how to
        // write in a specific format. QrCodeGeneratorImage is included with BoofCV and is used
        // to creates images
        MyQrCodeGenerator render = new MyQrCodeGenerator(4);

        render.render(qr);

        // Convert it to a BufferedImage for display purposes
        BufferedImage image = ConvertBufferedImage.convertTo(render.getGray(), null);

        // You can also save it to disk by uncommenting the line below
        UtilImageIO.saveImage(image, "qrcode.png");
    }
}
